<?php
	class HiringAction extends BaseAction {
		public function gwshow(){
			$hid = $_GET['hiring_id'];
			$list = D('Hiring')->hiring_show($hid);
			
			$this->assign('list',$list);
			$this->assign('workplace',format_workplace($list['store']));
			$this->assign('compic',$list['com_pic']);
			$this->display();
		}
		public function getarea(){
		$type = $_POST['type'];
		$aid = $_POST['aid'];
		$area  = getarea($type,$aid);
		exit(json_encode($area));
		}
		public function joblist(){
			$jianzhi = $_GET['jianzhi'];
			$hangye = D('hangye')->where('is_del = 0')->select();
			foreach($hangye as $k=>&$v){
				$v['posi'] = D('position')->where(array('hid'=>$v['id']))->select();
			}
			$this->assign('hangye',$hangye);
			$pro = getarea();
			$this->assign('pro',$pro);
			 if ($this->isPost()){
			 	if($_POST['pro']!=0){
			 		$area['pro'] = $_POST['pro'];
			 	}
			 	if($_POST['city']!=0){
			 		$area['city'] = $_POST['city'];
			 	}
			 	if($_POST['area']!=0){
			 		$area['area'] = $_POST['area'];
			 	}
			 	if(!empty($_POST['yxxl'])){
			 		$yxxl = $_POST['yxxl'];
			 		$map['pid'] = array('in',$yxxl);
			 	}
			 	
				$jobs = D('Hiring')->getsearchlist($jianzhi,$area,$map);
				
			 }else{
			 	$job_top = D('Hiring')->getlisttop();
				$jobs = D('Hiring')->getlist($jianzhi);
			 }
			$thispage = empty($_GET['p'])?1:$_GET['p'];
			$nextpage = $thispage+1;
			$uppage = $thispage-1;
			if($uppage<1){
				$uppage = 1;
			}
			if($jianzhi == 7){
				$this->assign('uppage',U('Hiring/joblist',array('jianzhi'=>7,'p'=>$uppage)));
				$this->assign('nextpage',U('Hiring/joblist',array('jianzhi'=>7,'p'=>$nextpage)));
			}else{
				$this->assign('uppage',U('Hiring/joblist',array('p'=>$uppage)));
				$this->assign('nextpage',U('Hiring/joblist',array('p'=>$nextpage)));
			}
			$this->assign('job_top',$job_top);
			$this->assign('jobs',$jobs);
			$this->display();
		}
		public function send_resume(){
			$map['uid'] = $_SESSION['member']['uid'];
			$map['is_del'] = 0;
			$member = D('member_info')->where($map)->find();
			$resume = D('resume')->where($map)->find();
			if(empty($member)){
				$this->ajaxReturn('','error',2);
				return false;
			}else{
				if($member['truename']=="" || $member['phone']=="" || $member['xingbie']=="" || $member['shengri']=="" || $member['face']==""){
					$this->ajaxReturn('','error',3);
					return false;
				}
			}
			if(empty($resume)){
				$this->ajaxReturn('','error',4);
				return false;
			}
			$data['hiring_id'] = $_POST['hiring_id'];
			$data['resume_id'] = $resume['resume_id'];
			$data['send_time'] = time();
			$data['from'] = 2;
			
			$awt=strtotime(date('Y-m-d'))-3600*24*7;
				$da['resume_id']=$resume['resume_id'];
			      $da['hiring_id']=$_POST['hiring_id'];
			      $da['send_time']=array('gt',$awt);
				$dd = D('send_resume')->where($da)->count('id');
				if($dd!=0){
					$this->ajaxReturn('','error',0);
				}else{
					$result = D('send_resume')->add($data);
					if($result){
						$id = mysql_insert_id();
						$resume_info = D('member_info')
											->join(C('DB_PREFIX').'resume ON '.C('DB_PREFIX').'resume.uid = '.C('DB_PREFIX').'member_info.uid')
											->where(C('DB_PREFIX').'member_info.uid = '.$_SESSION['member']['uid'])
											->find();
						$hiring_info = D('hiring')
											->join(C('DB_PREFIX').'hiring_info ON '.C('DB_PREFIX').'hiring.hiring_id = '.C('DB_PREFIX').'hiring_info.hiring_id')
											->where(C('DB_PREFIX').'hiring.hiring_id = '.$_POST['hiring_id'])
											->find();
						$exper_info = D('exper')->where('uid = '.$_SESSION['member']['uid'])->order('jobend DESC')->find();
						$manage = D('company_manage')->where('bid IN('.$hiring_info['notice'].')')->select();
						if(empty($exper_info)){
							$exper = '无';
						}else{
							$exper = $exper_info['jobname'].'|'.$exper_info['jobzhiwei'];
						}
						$data = array(
									'job' => array('value'=>$hiring_info['title'],'color'=>'#000'),
									'resuname' => array('value'=>$resume_info['truename'].'的简历','color'=>'#000'),
									'realname' => array('value'=>$resume_info['truename'],'color'=>'#000'),
									'exp' => array('value'=>$resume_info['jingyan'],'color'=>'#000'),
									'lastjob' => array('value'=>$exper,'color'=>'#000'),
									'remark' => array('value'=>'','color'=>'#000')
								);
						foreach($manage as $k => $v){
							$data['first'] = array('value'=>$v['wx_name']."，你好！\n你收到了一份新简历，请及时登录人才来了查阅。",'color'=>'#000');
							$url = 'http://www.rencailaile.com'.U('Companycontrol/resume_list',array('send_id'=>$id,'weixinmessage'=>1,'manage'=>$v['bid']));
							weixinmessage('newresume',$data,$v['wx_id'],$url);
						}
						$this->ajaxReturn('','success',1);
					}else{
						$this->ajaxReturn('','error',0);
					}
				}
			
		}
		
		public function nearhiring(){
			$uid = $_SESSION['member']['uid'];
			$location = D('member')->where('uid = '.$uid)->find();
			$max = D('Weixin')->getmax($location['map_x'],$location['map_y']);
			$hangye = D('hangye')->where('is_del = 0')->select();
			foreach($hangye as $k=>&$v){
				$v['posi'] = D('position')->where(array('hid'=>$v['id']))->select();
			}
			$this->assign('hangye',$hangye);
			$pro = getarea();
			$this->assign('pro',$pro);
			if ($this->isPost()){
			 	if($_POST['pro']!=0){
			 		$area['pro'] = $_POST['pro'];
			 	}
			 	if($_POST['city']!=0){
			 		$area['city'] = $_POST['city'];
			 	}
			 	if($_POST['area']!=0){
			 		$area['area'] = $_POST['area'];
			 	}
			 	if(!empty($_POST['yxxl'])){
			 		$yxxl = $_POST['yxxl'];
			 		$map['pid'] = array('in',$yxxl);
			 	}
				$jobs = D('Hiring')->getsearchlistbymax($area,$map,$max);
			}else{
				$jobs = D('Hiring')->getlistbymax($max,$location['map_x'],$location['map_y']);
			}
			$thispage = empty($_GET['p'])?1:$_GET['p'];
			$nextpage = $thispage+1;
			$uppage = $thispage-1;
			if($uppage<1){
				$uppage = 1;
			}
			$this->assign('uppage',U('Hiring/joblist',array('p'=>$uppage)));
			$this->assign('nextpage',U('Hiring/joblist',array('p'=>$nextpage)));
			$this->assign('jobs',$jobs);
			$this->display();
		}
	}
?>